package com.lxmes.sales.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.lxmes.sales.domain.NcProductPreSchedulingPlanMain;
import com.lxmes.sales.service.INcProductPreSchedulingPlanMainService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 产品预排产计划总Controller
 *
 * @author lx
 * @date 2023-04-17
 */
@Api(tags = "产品预排产计划总")
@RestController
@RequestMapping("/sales/productPreSchedulingPlanMain")
public class NcProductPreSchedulingPlanMainController extends BaseController
{
    @Autowired
    private INcProductPreSchedulingPlanMainService ncProductPreSchedulingPlanMainService;

    /**
     * 查询产品预排产计划总列表
     */
    @ApiOperation("查询产品预排产计划总列表")
    @PreAuthorize("@ss.hasPermi('sales:productPreSchedulingPlanMain:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcProductPreSchedulingPlanMain ncProductPreSchedulingPlanMain)
    {
        startPage();
        List<NcProductPreSchedulingPlanMain> list = ncProductPreSchedulingPlanMainService.selectNcProductPreSchedulingPlanMainList(ncProductPreSchedulingPlanMain);
        return getDataTable(list);
    }

    /**
     * 导出产品预排产计划总列表
     */
    @ApiOperation("导出产品预排产计划总列表")
    @PreAuthorize("@ss.hasPermi('sales:productPreSchedulingPlanMain:export')")
    @Log(title = "产品预排产计划总", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcProductPreSchedulingPlanMain ncProductPreSchedulingPlanMain)
    {
        List<NcProductPreSchedulingPlanMain> list = ncProductPreSchedulingPlanMainService.selectNcProductPreSchedulingPlanMainList(ncProductPreSchedulingPlanMain);
        ExcelUtil<NcProductPreSchedulingPlanMain> util = new ExcelUtil<NcProductPreSchedulingPlanMain>(NcProductPreSchedulingPlanMain.class);
        util.exportExcel(response, list, "产品预排产计划总数据");
    }

    /**
     * 获取产品预排产计划总详细信息
     */
    @ApiOperation("获取产品预排产计划总详细信息")
    @PreAuthorize("@ss.hasPermi('sales:productPreSchedulingPlanMain:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ncProductPreSchedulingPlanMainService.selectNcProductPreSchedulingPlanMainById(id));
    }

    /**
     * 新增产品预排产计划总
     */
    @ApiOperation("新增产品预排产计划总")
    @PreAuthorize("@ss.hasPermi('sales:productPreSchedulingPlanMain:add')")
    @Log(title = "产品预排产计划总", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcProductPreSchedulingPlanMain ncProductPreSchedulingPlanMain)
    {
        return toAjax(ncProductPreSchedulingPlanMainService.insertNcProductPreSchedulingPlanMain(ncProductPreSchedulingPlanMain));
    }

    /**
     * 修改产品预排产计划总
     */
    @ApiOperation("修改产品预排产计划总")
    @PreAuthorize("@ss.hasPermi('sales:productPreSchedulingPlanMain:edit')")
    @Log(title = "产品预排产计划总", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcProductPreSchedulingPlanMain ncProductPreSchedulingPlanMain)
    {
        return toAjax(ncProductPreSchedulingPlanMainService.updateNcProductPreSchedulingPlanMain(ncProductPreSchedulingPlanMain));
    }

    /**
     * 删除产品预排产计划总
     */
    @ApiOperation("删除产品预排产计划总")
    @PreAuthorize("@ss.hasPermi('sales:productPreSchedulingPlanMain:remove')")
    @Log(title = "产品预排产计划总", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ncProductPreSchedulingPlanMainService.deleteNcProductPreSchedulingPlanMainByIds(ids));
    }
    /**
     * 导入产品预排产计划总
     */
    @Log(title = "产品预排产计划总", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<NcProductPreSchedulingPlanMain> util = new ExcelUtil<>(NcProductPreSchedulingPlanMain.class);
        List<NcProductPreSchedulingPlanMain> ncProductPreSchedulingPlanMainList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = ncProductPreSchedulingPlanMainService.imporIteminfo(ncProductPreSchedulingPlanMainList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    // 下载模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<NcProductPreSchedulingPlanMain> util = new ExcelUtil<>(NcProductPreSchedulingPlanMain.class);
        util.importTemplateExcel(response,"产品预排产计划总");
    }

    /**
     * 删除产品预排产计划总
     */
    @ApiOperation("审核")
    @Log(title = "产品预排产计划总", businessType = BusinessType.DELETE)
    @GetMapping("/auditProduct/{ids}")
    public AjaxResult auditProduct(@PathVariable Long[] ids)
    {
        return toAjax(ncProductPreSchedulingPlanMainService.auditProduct(ids));
    }
}
